define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: '/mp/admin/mp_template',
        add_url: '/mp/admin/mp_template/create',
        edit_url: '/mp/admin/mp_template/edit',
        delete_url: '/mp/admin/mp_template/destroy',
        preview_url: '/mp/admin/mp_template/preview',
        make_url: '/mp/admin/mp_template/make',
    };

    var form = layui.form;

    return {

        index: function () {

            ea.table.render({
                init: init,
                cols: [[
                    {type: "checkbox"},
                    {field: 'name', minWidth: 80, title: '名称'},
                    {field: 'description', minWidth: 80, title: '备注'},
                    {field: 'created_at', minWidth: 120, title: '创建时间'},
                    {field: 'updated_at', minWidth: 120, title: '更新时间'},
                    {
                        width: 250,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '预览文章',
                                url: init.preview_url,
                                method: 'open',
                                auth: 'password',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            },{
                                text: '生成文章',
                                title: '确定生成文章？',
                                url: init.make_url,
                                method: 'get',
                                auth: 'password',
                                class: 'layui-btn layui-btn-xs',
                            }],
                            'edit',
                            'delete'
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        create: function () {

            this.ds_type();

            ea.listen();
        },
        edit: function () {

            this.ds_type();

            ea.listen();
        },
        ds_type: function () {
            form.on('radio(ds_type)', function (data) {
                $('.ds_type').hide();
                $('#' + data.value + '_type').show();
            });
        },
        preview: function () {
            ea.listen();
        },
        make: function () {
            ea.listen();
        }
    };
});
